<?php

namespace console\controllers;
use yii\db\Query;
use common\models\business\BusinessInspection;
use common\models\business\NewBusinessInspection;
use common\models\business\NewBusinessInspectionData;

class SiteController extends \yii\console\Controller
{


    public function actionIndex()
    {

        $list = (new Query())->select('*')
            ->from(BusinessInspection::tableName())
            ->where('id>=569')
            ->all();
        foreach ($list as $k => $row){
            $idata = [
                'business_person' => $row['business_person'],
                'pigid' => $row['pigid'],
                'createtime' => $row['createtime'],
                'business_personid' => $row['business_personid'],
                'lat' => $row['lat'],
                'lng' => $row['lng'],
                'address' => $row['address'],
                'status' => $row['status'],
                'remark' => $row['remark'],
                'is_del' => $row['is_del']
            ];
            \Yii::$app->db->createCommand()->insert(NewBusinessInspection::tableName(),$idata)->execute();
            $insid = \Yii::$app->db->lastInsertID;

            foreach ($row as $key => $v){

                $data = [
                    'inspectionid' => $insid,
                ];
                if($key == 'healthy'){
                    $data['fieldname'] = '健康状况';
                    $data['fieldtype'] = 'select';
                    $data['viewwidth'] = 'full';
                    $data['val'] = $v;
                }else if($key == 'healthy_desc'){
                    $data['fieldname'] = '健康总体描述';
                    $data['fieldtype'] = 'textarea';
                    $data['val'] = $v;
                }else if($key == 'weight'){
                    $data['fieldname'] = '体重';
                    $data['fieldtype'] = 'input';
                    $data['val'] = $v.'kg';
                }else if($key == 'length'){
                    $data['fieldname'] = '体长';
                    $data['fieldtype'] = 'input';
                    $data['val'] = $v;
                }else if($key == 'breath'){
                    $data['fieldname'] = '呼吸';
                    $data['fieldtype'] = 'select';
                    $data['val'] = $v.'次/分钟';
                }else if($key == 'width'){
                    $data['fieldname'] = '胸围';
                    $data['fieldtype'] = 'input';
                    $data['val'] = $v.'cm';
                }else if($key == 'activelevel'){
                    $data['fieldname'] = '精神状态';
                    $data['fieldtype'] = 'select';
                    $data['val'] = $v;
                }else if($key == 'cleanpen'){
                    $data['fieldname'] = '清圈';
                    $data['fieldtype'] = 'select';
                    $data['val'] = $v.'次/周';
                }else if($key == 'season'){
                    $data['fieldname'] = '季节';
                    $data['fieldtype'] = 'select';
                    $data['val'] = $v;
                }else if($key == 'disinfection'){
                    $data['fieldname'] = '消毒';
                    $data['fieldtype'] = 'select';
                    $data['val'] = $v.'次/周';
                }else if($key == 'haircolor'){
                    $data['fieldname'] = '毛色';
                    $data['fieldtype'] = 'select';
                    $data['val'] = $v;
                }else if($key == 'foodintake'){
                    $data['fieldname'] = '饮食';
                    $data['fieldtype'] = 'select';
                    $data['val'] = $v;
                }else if($key == 'urine'){
                    $data['fieldname'] = '尿色';
                    $data['fieldtype'] = 'select';
                    $data['val'] = $v;
                }else if($key == 'shit'){
                    $data['fieldname'] = '大便';
                    $data['fieldtype'] = 'select';
                    $data['val'] = $v;
                }else if($key == 'pen_temperature'){
                    $data['fieldname'] = '环境温度';
                    $data['fieldtype'] = 'select';
                    $data['val'] = $v.'℃';
                }else if($key == 'temperature'){
                    $data['fieldname'] = '体温';
                    $data['fieldtype'] = 'select';
                    $data['val'] = $v.'℃';
                }else if($key == 'situation'){
                    $data['fieldname'] = '体侧状态';
                    $data['fieldtype'] = 'select';
                    $data['val'] = $v;
                }else if($key == 'pigphoto'){
                    $data['fieldname'] = '仔猪照片';
                    $data['fieldtype'] = 'image';
                    $data['val'] = $v;
                }else if($key == 'pigpen'){
                    $data['fieldname'] = '猪舍环境';
                    $data['fieldtype'] = 'select';
                    $data['viewwidth'] = 'full';
                    $data['val'] = $v;
                }else if($key == 'pigpen_desc'){
                    $data['fieldname'] = '猪舍环境详情';
                    $data['fieldtype'] = 'textarea';
                    $data['val'] = $v;
                }else if($key == 'pigpen_photo'){
                    $data['fieldname'] = '猪舍环境照片';
                    $data['fieldtype'] = 'image';
                    $data['val'] = $v;
                }else if($key == 'feed'){
                    $data['fieldname'] = '食料情况';
                    $data['fieldtype'] = 'select';
                    $data['viewwidth'] = 'full';
                    $data['val'] = $v;
                }else if($key == 'feed_desc'){
                    $data['fieldname'] = '食料详情';
                    $data['fieldtype'] = 'textarea';
                    $data['val'] = $v;
                }else if($key == 'feed_photo') {
                    $data['fieldname'] = '食料照片';
                    $data['fieldtype'] = 'image';
                    $data['val'] = $v;
                }else{
                    continue;
                }
                \Yii::$app->db->createCommand()->insert(NewBusinessInspectionData::tableName(),$data)->execute();
            }
        }
    }




}